/**
 * 数据字典工具类
 */
import { useDictStoreWithOut } from '@/store/modules/dict'
import { ElementPlusInfoType } from '@/types/elementPlus'

const dictStore = useDictStoreWithOut()

/**
 * 获取 dictType 对应的数据字典数组
 *
 * @param dictType 数据类型
 * @returns {*|Array} 数据字典数组
 */
export interface DictDataType {
  dictType: string
  label: string
  value: string | number | boolean
  colorType: ElementPlusInfoType | ''
  cssClass: string
}

export const getDictOptions = (dictType: string) => {
  return dictStore.getDictByType(dictType) || []
}

export const getIntDictOptions = (dictType: string) => {
  const dictOption: DictDataType[] = []
  const dictOptions: DictDataType[] = getDictOptions(dictType)
  dictOptions.forEach((dict: DictDataType) => {
    dictOption.push({
      ...dict,
      value: parseInt(dict.value + '')
    })
  })
  return dictOption
}

export const getStrDictOptions = (dictType: string) => {
  const dictOption: DictDataType[] = []
  const dictOptions: DictDataType[] = getDictOptions(dictType)
  dictOptions.forEach((dict: DictDataType) => {
    dictOption.push({
      ...dict,
      value: dict.value + ''
    })
  })
  return dictOption
}

export const getBoolDictOptions = (dictType: string) => {
  const dictOption: DictDataType[] = []
  const dictOptions: DictDataType[] = getDictOptions(dictType)
  dictOptions.forEach((dict: DictDataType) => {
    dictOption.push({
      ...dict,
      value: dict.value + '' === 'true'
    })
  })
  return dictOption
}

export const getDictObj = (dictType: string, value: any) => {
  const dictOptions: DictDataType[] = getDictOptions(dictType)
  dictOptions.forEach((dict: DictDataType) => {
    if (dict.value === value.toString()) {
      return dict
    }
  })
}

/**
 * 获得字典数据的文本展示
 *
 * @param dictType 字典类型
 * @param value 字典数据的值
 */
export const getDictLabel = (dictType: string, value: any) => {
  const dictOptions: DictDataType[] = getDictOptions(dictType)
  const dictLabel = ref('')
  dictOptions.forEach((dict: DictDataType) => {
    if (dict.value === value?.toString()) {
      dictLabel.value = dict.label
    }
  })
  return dictLabel.value
}

export enum DICT_TYPE {
  USER_TYPE = 'user_type',
  COMMON_STATUS = 'common_status',
  SYSTEM_TENANT_PACKAGE_ID = 'system_tenant_package_id',
  // =========== 配置中心 模块 ===========
  DICT_ENABLE_STATUS = 'dict_enable_status',//配置中心-生产仓库-仓房库档案-仓库状态
  DICT_WAREHOUSE_ATTRIBUTE = 'dict_warehouse_attribute',//配置中心-生产仓库-仓房库档案-仓库属性
  CONFIG_POSITION_STATUS = 'config_position_status',  //组织管理-在职状态
  CONFIG_TEAM_STATUS = 'config_team_status',  //组织管理-班组状态
  CRAFT_PROCESS_NAME = 'craft_process_name',  //产品工序-产品工序名称
  DICT_IS_PRODUCTION = 'dict_is_production',  //产品工序-排产与否
  DICT_REPORT_WAY = 'dict_report_way',  //产品工序-报工方式
  DICT_PROCESS_STATUS = 'dict_process_status',  //产品工序-状态
  CONFIG_CRAFT_CUTTING_WEIGHT_MATERIAL_CATEGORY = 'config_craft_cutting_weight_material_category',
  CONFIG_CRAFT_CUTTING_WEIGHT_UNIT = 'config_craft_cutting_weight_unit',
  DICT_DEVICE_TYPE = 'dict_device_type', // 设备档案-设备类型
  DICT_DEVICE_STATUS = 'dict_device_status', // 设备档案-设备状态
  CONFIG_WAGE_MAN_HOUR_VALUATION_STATUS = 'config_wage_man_hour_valuation_status',//工时计价状态
  CONFIG_PRODUCT_TYPE = 'config_product_type', // 制图管理-流程单类型
  CONFIG_PROCESS_TEMPLATE_STATUS = 'config_process_template_status',// 制图管理-流程单状态
  DICT_IMPLEMENTATION_CYCLE='dict_implementation_cycle',//保养项目-实时周期
  DICT_FILLING_TYPE='dict_filling_type',//保养项目-填写类型
  CONFIG_MANUFACTURING_DETAILS_PROCESS_NAME = 'config_manufacturing_details_process_name',//配置中心-物料清单-制造件清单任务单-工序名称
  CONFIG_MANUFACTURING_DETAILS_CUTTING_PROCESS = 'config_manufacturing_details_cutting_process',//配置中心-物料清单-制造件清单任务单-下料工序
  CONFIG_MANUFACTURING_DETAILS_CUTTING_TYPE = 'config_wage_baiting_type',//配置中心-物料清单-制造件清单任务单-下料类型
  CONFIG_MANUFACTURING_DETAILS_STATUS = 'config_manufacturing_details_status',//配置中心-物料清单-制造件清单任务单详情-状态
  CONFIG_MANUFACTURING_PARTS_LIST_TASK_STATUS = 'config_manufacturing_parts_list_task_status',//配置中心-物料清单-制造件清单任务单-状态
  // CRAFT_PROCESS_NAME='craft_process_name', // 配置中心 - 工序计价
  CONFIG_QUALITY_TEMPLATE_STATUS='config_quality_template_status', // 配置中心 -- 质量管理
  CONFIG_QUALITY_INSPECT_TYPE='config_quality_inspect_type', // 配置中心 -- 质量管理 -- 检验报告模板
  CONFIG_WAGE_PAINT_STATUS='config_wage_paint_status', // 配置中心 -- 工资考核 -- 油漆电工单价状态
  CONFIG_WAGE_PROCESS_VALUATION_STATUS='config_wage_process_valuation_status', // 配置中心 -- 工资考核 -- 价目表
  MACHINING_STATUS='machining_status',// 配置中心 -- 工资考核 -- 机加加工单价 -- 状态
  CONFIG_WAGE_VALUATION_UNIT='config_wage_valuation_unit', // 配置中心 -- 工序计价使用
  CONFIG_WAGE_CRAFT_TYPE='config_wage_craft_type', // 配置中心 -- 工序计价 -- 工艺类型
  CONFIG_WAGE_BAITING_TYPE='config_wage_baiting_type',// 配置中心 -- 工序计价 -- 下料类型
  MACHINING_PROCESS='machining_process', // 配置中心 -- 价目表 -- 机加工序
  DICT_RELATION_TYPE ="dict_relation_type", // 工艺路线详情关系类型 
  DICT_ABNORMAL_TYPE = 'dict_abnormal_type',
  DICT_CONCURRENCY = 'dict_concurrency',
  DICT_COMPARE = 'dict_compare',
  // =========== 订单管理 模块 ===========
  MARKET_ORDER_TYPE = 'market_order_type',
  ORDER_TASK_TYPE = 'order_task_type',
  ORDER_TASK_STATUS= 'order_task_status',
  TASK_STATUS = 'task_status',
  TASK_TYPE = 'task_type',
  CHANGE_TYPE = 'change_type',
  ORDER_TYPE = 'order_type',
  SALE_TYPE = 'sale_type',//销售类型
  BUSINESS_TYPE = 'business_type',
  MARKET_ORDER_STATUS = 'market_order_status',//订单状态
  DELIVERY_PROJECT_TYPE = 'delivery_project_type',//交货项目类型
  ORDER_PRODUCT_UNIT = 'order_product_unit',//产品信息单位
  ORDER_TECHNOL_TASK_TYPE = 'order_technol_task_type',
  ORDER_TECHNOL_TASK_STATUS = 'order_technol_task_status',
  ORDER_TASK_BOOK_STATUS = 'order_task_book_status',
  INCOMING_TYPE = 'incoming_type',
  // =========== 外协管路 模块 ===========
  DICT_OUTSOURCE_MODE= 'dict_outsource_mode',//委外方式
  IS_MACHINING = 'is_machining',//是否机加
  DICT_MATTER = 'dict_matter',
  DICT_DEPT_WORD = 'dict_dept_word',
  // ========== 生产管理 ==========
  SHIPPING_TASK_ORDER_STATUS = 'shipping_task_order_status',
  DICT_PREPARE_STATUS= 'dict_prepare_status',
  // ========== SYSTEM 模块 ==========
  SYSTEM_USER_SEX = 'system_user_sex',
  SYSTEM_MENU_TYPE = 'system_menu_type',
  SYSTEM_ROLE_TYPE = 'system_role_type',
  SYSTEM_DATA_SCOPE = 'system_data_scope',
  SYSTEM_NOTICE_TYPE = 'system_notice_type',
  SYSTEM_OPERATE_TYPE = 'system_operate_type',
  SYSTEM_LOGIN_TYPE = 'system_login_type',
  SYSTEM_LOGIN_RESULT = 'system_login_result',
  SYSTEM_SMS_CHANNEL_CODE = 'system_sms_channel_code',
  SYSTEM_SMS_TEMPLATE_TYPE = 'system_sms_template_type',
  SYSTEM_SMS_SEND_STATUS = 'system_sms_send_status',
  SYSTEM_SMS_RECEIVE_STATUS = 'system_sms_receive_status',
  SYSTEM_ERROR_CODE_TYPE = 'system_error_code_type',
  SYSTEM_OAUTH2_GRANT_TYPE = 'system_oauth2_grant_type',
  SYSTEM_MAIL_SEND_STATUS = 'system_mail_send_status',
  SYSTEM_NOTIFY_TEMPLATE_TYPE = 'system_notify_template_type',

  // ========== INFRA 模块 ==========
  INFRA_BOOLEAN_STRING = 'infra_boolean_string',
  INFRA_JOB_STATUS = 'infra_job_status',
  INFRA_JOB_LOG_STATUS = 'infra_job_log_status',
  INFRA_API_ERROR_LOG_PROCESS_STATUS = 'infra_api_error_log_process_status',
  INFRA_CONFIG_TYPE = 'infra_config_type',
  INFRA_CODEGEN_TEMPLATE_TYPE = 'infra_codegen_template_type',
  INFRA_CODEGEN_FRONT_TYPE = 'infra_codegen_front_type',
  INFRA_CODEGEN_SCENE = 'infra_codegen_scene',
  INFRA_FILE_STORAGE = 'infra_file_storage',

  // ========== BPM 模块 ==========
  BPM_MODEL_CATEGORY = 'bpm_model_category',
  BPM_MODEL_FORM_TYPE = 'bpm_model_form_type',
  BPM_TASK_ASSIGN_RULE_TYPE = 'bpm_task_assign_rule_type',
  BPM_PROCESS_INSTANCE_STATUS = 'bpm_process_instance_status',
  BPM_PROCESS_INSTANCE_RESULT = 'bpm_process_instance_result',
  BPM_TASK_ASSIGN_SCRIPT = 'bpm_task_assign_script',
  BPM_OA_LEAVE_TYPE = 'bpm_oa_leave_type',

  // ========== PAY 模块 ==========
  PAY_CHANNEL_WECHAT_VERSION = 'pay_channel_wechat_version', // 微信渠道版本
  PAY_CHANNEL_ALIPAY_SIGN_TYPE = 'pay_channel_alipay_sign_type', // 支付渠道支付宝算法类型
  PAY_CHANNEL_ALIPAY_MODE = 'pay_channel_alipay_mode', // 支付宝公钥类型
  PAY_CHANNEL_ALIPAY_SERVER_TYPE = 'pay_channel_alipay_server_type', // 支付宝网关地址
  PAY_CHANNEL_CODE_TYPE = 'pay_channel_code_type', // 支付渠道编码类型
  PAY_ORDER_NOTIFY_STATUS = 'pay_order_notify_status', // 商户支付订单回调状态
  PAY_ORDER_STATUS = 'pay_order_status', // 商户支付订单状态
  PAY_ORDER_REFUND_STATUS = 'pay_order_refund_status', // 商户支付订单退款状态
  PAY_REFUND_ORDER_STATUS = 'pay_refund_order_status', // 退款订单状态
  PAY_REFUND_ORDER_TYPE = 'pay_refund_order_type', // 退款订单类别

  // ========== MP 模块 ==========
  MP_AUTO_REPLY_REQUEST_MATCH = 'mp_auto_reply_request_match', // 自动回复请求匹配类型
  MP_MESSAGE_TYPE = 'mp_message_type', // 消息类型

  // ========== MALL 模块 ==========
  PRODUCT_UNIT = 'product_unit', // 商品单位
  PRODUCT_SPU_STATUS = 'product_spu_status', //商品状态
  // ========== MALL 交易模块 ==========
  EXPRESS_CHARGE_MODE = 'trade_delivery_express_charge_mode', //快递的计费方式
  //积分模块//
  POINT_BIZ_TYPE = 'point_biz_type',
  POINT_STATUS = 'point_status'
}
